<template>
  <div class="admin-home">
    <h2>管理员控制台</h2>
    
    <!-- 数据统计卡片 -->
    <el-row :gutter="20" class="statistics">
      <el-col :span="6">
        <el-card class="stat-card">
          <template #header>
            <div class="card-header">
              <span>总用户数</span>
            </div>
          </template>
          <div class="stat-value">{{ statistics.userCount }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <template #header>
            <div class="card-header">
              <span>药品种类</span>
            </div>
          </template>
          <div class="stat-value">{{ statistics.drugCount }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <template #header>
            <div class="card-header">
              <span>待处理订单</span>
            </div>
          </template>
          <div class="stat-value">{{ statistics.pendingOrders }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <template #header>
            <div class="card-header">
              <span>今日销售额</span>
            </div>
          </template>
          <div class="stat-value">¥{{ statistics.todaySales }}</div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 快捷操作 -->
    <div class="quick-actions">
      <h3>快捷操作</h3>
      <el-row :gutter="20">
        <el-col :span="6" v-for="action in quickActions" :key="action.path">
          <el-card class="action-card" @click="handleQuickAction(action.path)">
            <el-icon :size="24" class="action-icon">
              <component :is="action.icon" />
            </el-icon>
            <div class="action-title">{{ action.title }}</div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 最近订单 -->
    <div class="recent-orders">
      <div class="section-header">
        <h3>最近订单</h3>
        <el-button type="primary" link @click="$router.push('/admin/orders')">
          查看全部
        </el-button>
      </div>
      <el-table :data="recentOrders" style="width: 100%">
        <el-table-column prop="id" label="订单号" width="180" />
        <el-table-column prop="user" label="用户" width="120" />
        <el-table-column prop="amount" label="金额" width="120" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-tag :type="getOrderStatusType(scope.row.status)">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="180" />
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import {
  Plus,
  List,
  Document,
  Bell
} from '@element-plus/icons-vue'

const router = useRouter()

// 统计数据
const statistics = ref({
  userCount: 0,
  drugCount: 0,
  pendingOrders: 0,
  todaySales: 0
})

// 快捷操作
const quickActions = [
  { title: '添加药品', path: '/admin/drugs', icon: Plus },
  { title: '分类管理', path: '/admin/categories', icon: List },
  { title: '订单管理', path: '/admin/orders', icon: Document },
  { title: '发布公告', path: '/admin/announcements', icon: Bell }
]

// 最近订单
const recentOrders = ref([])

// 处理快捷操作点击
const handleQuickAction = (path) => {
  router.push(path)
}

// 获取订单状态对应的标签类型
const getOrderStatusType = (status) => {
  const statusMap = {
    '待处理': 'warning',
    '已发货': 'primary',
    '已完成': 'success',
    '已取消': 'info'
  }
  return statusMap[status] || 'info'
}

// 加载数据
onMounted(async () => {
  // TODO: 从API获取实际数据
  // 这里使用模拟数据
  statistics.value = {
    userCount: 128,
    drugCount: 56,
    pendingOrders: 12,
    todaySales: 15680
  }

  recentOrders.value = [
    {
      id: 'DD20240101001',
      user: '张三',
      amount: 299,
      status: '待处理',
      createTime: '2024-01-01 10:00:00'
    },
    // 添加更多模拟数据...
  ]
})
</script>

<style scoped>
.admin-home {
  padding: 20px;
}

.statistics {
  margin-bottom: 30px;
}

.stat-card {
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
}

.quick-actions {
  margin-bottom: 30px;
}

.action-card {
  cursor: pointer;
  text-align: center;
  padding: 20px;
  transition: all 0.3s;
}

.action-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.action-icon {
  margin-bottom: 10px;
  color: #409EFF;
}

.action-title {
  font-size: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.recent-orders {
  margin-top: 30px;
}
</style> 